Skip to content

Remove enclosed_thr feature of distance_masks which seems to be broken - #1593

Open
ethanbb wants to merge 2 commits into
flatironinstitute:devfrom
proektlab:remove-enclosed-thr
Open

ethanbb wants to merge 2 commits into
flatironinstitute:devfrom
proektlab:remove-enclosed-thr

Conversation

@ethanbb

@ethanbb ethanbb commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Description

I am using the distance_masks and register_ROIs functions, and while I've always kept enclosed_thr as None, I just noticed that it seems to be broken in the following ways:

  • In these lines:

    CaImAn/caiman/base/rois.py

    Lines 781 to 783 in 240e1f2

    if enclosed_thr is not None:
    if intersection == gt_val[j] or intersection == gt_val[i]:
    D[i, j] = min(D[i, j], 0.5)
    gt_val is indexed by j, but j iterates over the test components, so it's meaningless as far as I can tell and may be out of bounds
  • Behavior does not match the documentation - it always sets the distance to be at max 0.5, rather than the value of enclosed_thr.

The feature is a bit weird, anyway - according to how I think it's supposed to work, the distance is allowed to be high if there is one pixel of ground truth outside of the test component, but as soon as it's fully enclosed it jumps to this threshold. We could fix it instead of removing it, but in all the examples it's just set to None, so I don't think it's worth keeping.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would break back-compatibility)

Has your PR been tested?

caimanmanager test and caimanmanager demotest both pass for me on Linux.

@ethanbb

ethanbb commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Hmm, the CI seems to be having trouble starting due to failure to install "libglapi-mesa." All I know is that's some graphics library.

@pgunn
pgunn changed the base branch from main to dev November 7, 2026 11:24
@pgunn

pgunn commented Nov 7, 2026

Copy link
Copy Markdown
Member

I think the testing framework depends on an older OS image and I need to switch images for CI to work again. Chances are it'll be 3 lines of code after maybe an hour or two of study. ^_^

Nothing to do with the contents of the PR; it's broken for the other recent PRs too.

return T.Compose(transforms)


def distance_masks(M_s:list, cm_s:list[list], max_dist: float, enclosed_thr:Optional[float] = None) -> list:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed duplicated function; importing from caiman.base.rois instead

@eeshaanjum eeshaanjum mentioned this pull request Nov 12, 2026
@pgunn

pgunn commented Nov 14, 2026

Copy link
Copy Markdown
Member

I think if you rebase the tests will either run or fail in the correct way

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants